﻿
namespace Pepper.Cloud.Site.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Pepper.Core;

    [HandleError]
    public class HomeController : Controller
    {
        [HttpGet]
        public ActionResult Index()
        {
            ViewData.Add("settings-count", Settings.SettingsCount());
            return View();
        }

        [HttpPost]
        public ActionResult Index(string username, string password)
        {
            try
            {
                var userid = Settings.Login(username, password);
                bool settingsPublic = Settings.AreSettingsPublic(userid);
                TempData.Add("userid", userid);
                ViewData.Add("settings-public", settingsPublic);
                ViewData.Add("settings-count", Settings.SettingsCount());
                if (settingsPublic)
                {
                    ViewData.Add("userid", userid);
                }
            }
            catch (PepperCoreException err)
            {
                ViewData.Add("pepper-message", err.Message);
            }

            return View();
        }
    }
}
